package cn.hznc.controller.inventory;


import cn.hznc.aspect.BusinessType;
import cn.hznc.aspect.Log;
import cn.hznc.domain.entity.ToolPartEntity;
import cn.hznc.domain.request.inventory.*;
import cn.hznc.domain.request.toolAnalyze.ToolConsumptionandUsageAnalysisReq;
import cn.hznc.domain.response.PageResult;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.controller.service.inventory.ToolPartsInventoryService;
import cn.hznc.exception.ToolLifeCycleException;
import cn.hznc.vo.ToolInventoryVo;
import cn.hznc.vo.UpdateLocationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：Administrator
 * @Date：2023/3/27 11:48
 */
@RestController
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/toolPartInventory")
public class ToolPartsInventoryController {

    @Autowired
    private ToolPartsInventoryService toolPartsInventoryService;

    @RequestMapping(value = "/getToolPartsManageShelvesList",method = RequestMethod.POST)
    public ResponseBody getToolPartsManageShelvesList(@RequestBody ToolPartsManageReq toolPartsManageReq){
        return ResponseBody.success(toolPartsInventoryService.getToolPartsManageShelvesList(toolPartsManageReq));
    }

    @RequestMapping(value = "/getToolPartsManageList",method = RequestMethod.POST)
    public ResponseBody getToolPartsManageList(@RequestBody ToolPartsManageReq toolPartsManageReq){
        return ResponseBody.success(toolPartsInventoryService.getToolPartsInventoryList(toolPartsManageReq));
    }

    @RequestMapping(value = "/editToolPartsSafetyStock",method = RequestMethod.POST)
    @Log(title = "编辑库位安全库存" , businessType = BusinessType.UPDATE)
    public ResponseBody editToolPartsSafetyStock(@RequestBody EditToolPartsSafetyStockReq editToolPartsSafetyStockReq){
        return ResponseBody.success(toolPartsInventoryService.editToolPartsSafetyStock(editToolPartsSafetyStockReq));
    }


    @RequestMapping(value = "/getToolPartsDetail",method = RequestMethod.POST)
    public ResponseBody getToolPartsDetail(@RequestBody InventoryManageDetailReq inventoryManageDetailReq){
        return ResponseBody.success(toolPartsInventoryService.getToolPartsDetailList(inventoryManageDetailReq));
    }

    @RequestMapping(value = "/getToolPartsLocationDetail",method = RequestMethod.POST)
    public ResponseBody getToolPartsLocationDetail(@RequestBody InventoryManageDetailReq inventoryManageDetailReq){
        return ResponseBody.success(toolPartsInventoryService.getToolPartsLocationDetail(inventoryManageDetailReq));
    }

    @RequestMapping(value = "/editLocationTool",method = RequestMethod.POST)
    public ResponseBody editLocationTool(@RequestBody EditLocationToolReq editLocationToolReq){
        return ResponseBody.success(toolPartsInventoryService.editLocationTool(editLocationToolReq));
    }

    @RequestMapping(value = "/editLocationToolDetail",method = RequestMethod.POST)
    public ResponseBody editLocationToolDetail(@RequestBody EditLocationToolReq editLocationToolReq){
        return ResponseBody.success(toolPartsInventoryService.editLocationToolDetail(editLocationToolReq));
    }

    @RequestMapping(value = "/queryAllToolPart", method = RequestMethod.POST)
    public ResponseBody queryAllToolPart(@RequestBody QryAllToolPartReq qryAllToolPartReq){
        return ResponseBody.success(toolPartsInventoryService.qryAllToolPart(qryAllToolPartReq));
    }

    @RequestMapping(value = "/queryAllToolPart1", method = RequestMethod.POST)
    public ResponseBody<PageResult<ToolPartEntity>> queryAllToolPart1(@RequestBody QueryAllToolPartReq queryAllToolPartReq){
        return ResponseBody.success(toolPartsInventoryService.queryAllToolPart(queryAllToolPartReq));
    }

    @org.springframework.web.bind.annotation.ResponseBody
    @RequestMapping(value = "/updateLocation", method = RequestMethod.POST)
    public ResponseBody updateLocation(@RequestBody UpdateLocationVo toolInventoryVo) throws ToolLifeCycleException {
        toolPartsInventoryService.updateLocation(toolInventoryVo);
        return ResponseBody.success();
    }

    @RequestMapping(value = "/queryNoManagementToolPart", method = RequestMethod.POST)
    public ResponseBody queryNoManagementToolPart(@RequestBody ToolPartsManageReq toolPartsManageReq){
        return ResponseBody.success(toolPartsInventoryService.queryNoManagementToolPart(toolPartsManageReq));
    }

    @RequestMapping(value = "/queryNoManagementToolParts", method = RequestMethod.POST)
    public ResponseBody queryNoManagementToolParts(@RequestBody NoManagementReq noManagementReq){
        return ResponseBody.success(toolPartsInventoryService.queryNoManagementToolParts(noManagementReq));
    }

    @RequestMapping(value = "/qryAssemblyToolByShankRfid", method = RequestMethod.GET)
    public ResponseBody qryAssemblyToolByShankRfid(@RequestParam("shankRfid") String shankRfid){
        return ResponseBody.success(toolPartsInventoryService.qryAssemblyToolByShankRfid(shankRfid));
    }

    @RequestMapping(value = "/unbindingAssemblyTool", method = RequestMethod.POST)
    public ResponseBody unbindingAssemblyTool(@RequestBody UnbindingAssemblyToolReq unbindingAssemblyToolReq){
        try {
            return ResponseBody.success(toolPartsInventoryService.unbindingAssemblyTool(unbindingAssemblyToolReq));
        } catch (ToolLifeCycleException e) {
            return ResponseBody.error(e.getCode() , e.getMsg());
        }
    }

    @RequestMapping(value = "/queryStatusByLocationId", method = RequestMethod.GET)
    public ResponseBody queryStatusByLocationId(@RequestParam("locationId") Integer locationId){
        return ResponseBody.success(toolPartsInventoryService.queryStatusByLocationId(locationId));
    }

    @RequestMapping(value = "/queryStatusByLocationIdReload", method = RequestMethod.GET)
    public ResponseBody queryStatusByLocationIdReload(@RequestParam("locationId") Integer locationId){
        return ResponseBody.success(toolPartsInventoryService.queryStatusByLocationIdReload(locationId));
    }

    @RequestMapping(value = "/qryByRfid", method = RequestMethod.GET)
    public ResponseBody qryByRfid(@RequestParam("rfid") String rfid){
        return ResponseBody.success(toolPartsInventoryService.qryByRfid(rfid));
    }

    @RequestMapping(value = "/updateToolPartFlag", method = RequestMethod.GET)
    //@Log(title = "编辑" , businessType = BusinessType.INSERT)
    public ResponseBody updateToolPartFlag(){
        return ResponseBody.success(toolPartsInventoryService.updateToolPartFlag());
    }

    @RequestMapping(value = "/updateToolPartLifeRate", method = RequestMethod.GET)
    public ResponseBody updateToolPartLifeRate(){
        return ResponseBody.success(toolPartsInventoryService.updateToolPartLifeRate());
    }

    @RequestMapping(value = "/deletePartOfToolInventoryData", method = RequestMethod.GET)
    public ResponseBody deletePartOfToolInventoryData(){
        return ResponseBody.success(toolPartsInventoryService.deletePartOfToolInventoryData());
    }


}
